using Cysharp.Threading.Tasks;

namespace EventBus
{
    /// <summary>
    /// 异步发送，并期望得到返回值
    /// </summary>
    public partial class EventBusImpl
    {
        public async UniTask<TResult> BroadcastAndReturnAsync<TResult>(object sender, string eventName)
        {
            var broadcast  = GetOrCreateBroadcast(eventName);
            return await broadcast .BroadcastFuncAsync<int, int, int, int, int, int, int, int, TResult>(eventName, 0, default, default, default, default, default, default, default, default);
        }

        public async UniTask<TResult> BroadcastAndReturnAsync<T1, TResult>(object sender, string eventName, T1 arg1)
        {
            var broadcast  = GetOrCreateBroadcast(eventName);
            return await broadcast .BroadcastFuncAsync<T1, int, int, int, int, int, int, int, TResult>(eventName, 1, arg1, default, default, default, default, default, default, default);
        }

        public async UniTask<TResult> BroadcastAndReturnAsync<T1, T2, TResult>(object sender, string eventName, T1 arg1,
            T2 arg2)
        {
            var broadcast  = GetOrCreateBroadcast(eventName);
            return await broadcast .BroadcastFuncAsync<T1, T2, int, int, int, int, int, int, TResult>(eventName, 2, arg1, arg2, default, default, default, default, default, default);
        }

        public async UniTask<TResult> BroadcastAndReturnAsync<T1, T2, T3, TResult>(object sender, string eventName, T1 arg1,
            T2 arg2, T3 arg3)
        {
            var broadcast  = GetOrCreateBroadcast(eventName);
            return await broadcast .BroadcastFuncAsync<T1, T2, T3, int, int, int, int, int, TResult>(eventName, 3, arg1, arg2, arg3, default, default, default, default, default);
        }

        public async UniTask<TResult> BroadcastAndReturnAsync<T1, T2, T3, T4, TResult>(object sender, string eventName,
            T1 arg1, T2 arg2, T3 arg3, T4 arg4)
        {
            var broadcast  = GetOrCreateBroadcast(eventName);
            return await broadcast .BroadcastFuncAsync<T1, T2, T3, T4, int, int, int, int, TResult>(eventName, 4, arg1, arg2, arg3, arg4, default, default, default, default);
        }

        public async UniTask<TResult> BroadcastAndReturnAsync<T1, T2, T3, T4, T5, TResult>(object sender, string eventName,
            T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
        {
            var broadcast  = GetOrCreateBroadcast(eventName);
            return await broadcast .BroadcastFuncAsync<T1, T2, T3, T4, T5, int, int, int, TResult>(eventName, 5, arg1, arg2, arg3, arg4, arg5, default, default, default);
        }

        public async UniTask<TResult> BroadcastAndReturnAsync<T1, T2, T3, T4, T5, T6, TResult>(object sender,
            string eventName,
            T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
        {
            var broadcast  = GetOrCreateBroadcast(eventName);
            return await broadcast .BroadcastFuncAsync<T1, T2, T3, T4, T5, T6, int, int, TResult>(eventName, 6,
                arg1, arg2, arg3, arg4, arg5, arg6, default, default);
        }

        public async UniTask<TResult> BroadcastAndReturnAsync<T1, T2, T3, T4, T5, T6, T7, TResult>(object sender,
            string eventName,
            T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7)
        {
            var broadcast  = GetOrCreateBroadcast(eventName);
            return await broadcast .BroadcastFuncAsync<T1, T2, T3, T4, T5, T6, T7, int, TResult>(eventName, 7,
                arg1, arg2, arg3, arg4, arg5, arg6, arg7, default);
        }

        public async UniTask<TResult> BroadcastAndReturnAsync<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(object sender,
            string eventName,
            T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8)
        {
            var broadcast  = GetOrCreateBroadcast(eventName);
            return await broadcast .BroadcastFuncAsync<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(eventName, 8,
                arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
        }
    }
}